const socketUav = new WebSocket('ws://150.158.186.245:80/k/jtac');
const socketOrderLog  = new WebSocket('ws://150.158.186.245:80/k/orderLog');
// const socketUav = new WebSocket('ws://localhost:8000/k/jtac');
// const socketOrderLog  = new WebSocket('ws://localhost:8000/k/orderLog');
// 添加防抖函数
const debounceUpdate = debounce(updateGaugeData, 100);

socketUav.onmessage = function (event) {
    const data = JSON.parse(event.data);
    console.log('Received data:', data);
    // 更新无人机位置信息
    let jtac_lon = document.getElementById('jtac-lon')
    let jtac_lat = document.getElementById('jtac-lat')
    jtac_lon.innerHTML = data.longitude.toFixed(5);  // 更新经度
    jtac_lat.innerHTML = data.latitude.toFixed(5);  // 更新纬度
    //更新无人机状态信息
    debounceUpdate(data);
};

socketOrderLog.onmessage = function (event) {
    const data = JSON.parse(event.data);
    console.log('Received data:', data);
    addLogEntry(data["from"],data["instruction"])
};

// 防抖函数实现
function debounce(func, wait) {
    let timeout;
    return function(...args) {
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(this, args), wait);
    };
}